/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * @Title: TestHttps.java
 * @Package phoenics.apeak.simple.service
 * @Description
 * @author phoenics@126com
 * @date 2016-1-30 16:01:32
 * @version V1.0
 */
package phoenics.apeak.simple.service;

import java.util.Base64;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.BufferingResponseListener;

import org.eclipse.jetty.util.ssl.SslContextFactory;
// TODO: Auto-generated Javadoc
//import org.eclipse.jetty.http2.client.HTTP2Client;

/**
 * The Class TestHttps.
 *
 * @Description The Class TestHttps.
 */
public class TestHttps {
	//public static final String JAVAX_NET_SSL_KEY_STORE = "javax.net.ssl.keyStore"; 
   // public static final String JAVAX_NET_SSL_KEY_STORE_PASSWORD = "javax.net.ssl.keyStorePassword"; 
	/**
 * The main method.
 *
 * @param args
 *            the arguments
 * @Description The main method.
 */
	public static void main(String[] args) {
		 //String keyStorePath = System.getProperty(JAVAX_NET_SSL_KEY_STORE); 
		// String keyStorePassword = System.getProperty(JAVAX_NET_SSL_KEY_STORE_PASSWORD); 
		try {
		SslContextFactory sslContextFactory = new SslContextFactory();
		//sslContextFactory.getKeyStore().getType()
	//	System.out.println("===getKeyStorePath======"+sslContextFactory.getKeyStore().getType() );
		//System.out.println("===keyStorePath======"+keyStorePath );d:/trust.keystore
		//sslContextFactory.setKeyStorePath("d:/keystore");
     //  sslContextFactory.setKeyStorePassword("123456");
        //sslContextFactory.setTrustStorePath("d:/keystore");
      //  sslContextFactory.setTrustStorePassword("123456");
	//	sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");
		//HTTP2Client http2Client = new HTTP2Client();
		// Instantiate HttpClient with the SslContextFactory
		HttpClient httpClient = new HttpClient(sslContextFactory);
		// private String keyStorePath = System.getProperty(JAVAX_NET_SSL_KEY_STORE); 
	   // private String keyStorePassword = System.getProperty(JAVAX_NET_SSL_KEY_STORE_PASSWORD); 
		//httpClient.
		// Configure HttpClient, for example:
		//httpClient.setFollowRedirects(false);
		//httpClient.addBean(sslContextFactory);
		// Start HttpClient
		
		//getKeyStorePath() 
			httpClient.start();
			Request r=httpClient.newRequest("https://resources.shopstyle.com/sim/d6/93/d693b54b7bbbc57d34e795f1cccfe8f8/prada-saffiano-logo-belt-black.jpg");
		//	r.
			//r.scheme("https");
			//System.out.println("===getKeyStorePath======"+sslContextFactory.getKeyStorePath() );
			//System.out.println("===11======"+r.getScheme());
			System.out.println("===11======"+r.getScheme());
			r.send(new BufferingResponseListener(){

				@Override
				public void onComplete(Result result) {
					String c=Base64.getEncoder().encodeToString(this.getContent());
					System.out.println("========="+c);
				}
				
			});
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
